package com.fit.entities;

import java.text.SimpleDateFormat;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.apache.tapestry5.beaneditor.NonVisual;
import org.apache.tapestry5.beaneditor.Validate;

@Entity
@Table(name = "registration")
public class Registration {

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@NonVisual
	@Column(name = "id")
	private Long id;
	@Validate("required")
	@Column(name = "date_of_registration", nullable = false)
	private Date date;
	@Validate("required")
	@Column(name = "expiry_date", nullable = false)
	private Date expiryDate;
	@Validate("required")
	@Column(name = "price", nullable = false)
	private double price;
	@Validate("required")
	@NonVisual
	@Column(name = "active", nullable = true)
	private boolean active;
	@Validate("required")
	@ManyToOne(optional = false)
	@JoinColumn(name = "registration_licencePlate")
	private LicencePlate licencePlate;
	@Validate("required")
	@ManyToOne(optional = false)
	@JoinColumn(name = "registration_company")
	private Company company;

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}
	public double getPrice() {
		return price;
	}

	public void setPrice(double price) {
		this.price = price;
	}

	public boolean isActive() {
		return active;
	}

	public void setActive(boolean active) {
		this.active = active;
	}

	public LicencePlate getLicencePlate() {
		return licencePlate;
	}

	public void setLicencePlate(LicencePlate licencePlate) {
		this.licencePlate = licencePlate;
	}

	public Date getDate() {
		return date;
	}

	public void setDate(Date date) {
		this.date = date;
	}

	public Date getExpiryDate() {
		return expiryDate;
	}
	
	public String getExpiryDateFormat() {
		SimpleDateFormat sf = new SimpleDateFormat("dd.MM.yyyy");
		String s = sf.format(expiryDate);
		return s;
	}
	
	public String getDateFormat() {
		SimpleDateFormat sf = new SimpleDateFormat("dd.MM.yyyy");
		String s = sf.format(date);
		return s;
	}

	public void setExpiryDate(Date expiryDate) {
		this.expiryDate = expiryDate;
	}

	public Company getCompany() {
		return company;
	}

	public void setCompany(Company company) {
		this.company = company;
	}

}
